package com.ruoyi.web.controller.laiqianba.merchantdata;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.laiqianba.service.IAdminHttpService;
import com.ruoyi.merchantdata.enums.DataStatusEnum;
import com.ruoyi.merchantdata.enums.StarTypeEnum;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.MerchantDataAllocateInfo;
import com.ruoyi.merchantdata.service.IMerchantDataAllocateInfoService;
import com.ruoyi.web.wrapper.MerchantDataAllocateInfoWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公海数据分配Controller
 * 
 * @author ruoyi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/merchantdata/allocateInfo")
public class MerchantDataAllocateInfoController extends BaseController
{
    @Autowired
    private IMerchantDataAllocateInfoService merchantDataAllocateInfoService;
    @Autowired
    IAdminHttpService adminHttpService;

    /**
     * 查询公海数据分配列表
     */
    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantDataAllocateInfo merchantDataAllocateInfo)
    {
        startPage();
        List<Map<String, Object>> list = merchantDataAllocateInfoService.selectMerchantDataAllocateInfoMapList(merchantDataAllocateInfo);
        list = new MerchantDataAllocateInfoWrapper(list).wrap();
        return getDataTable(list);
    }


    /**
     * 导出公海数据分配列表
     */
    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:export')")
    @Log(title = "公海数据分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantDataAllocateInfo merchantDataAllocateInfo)
    {
        List<MerchantDataAllocateInfo> list = merchantDataAllocateInfoService.selectMerchantDataAllocateInfoList(merchantDataAllocateInfo);
        ExcelUtil<MerchantDataAllocateInfo> util = new ExcelUtil<MerchantDataAllocateInfo>(MerchantDataAllocateInfo.class);
        util.exportExcel(response, list, "公海数据分配数据");
    }

    /**
     * 获得枚举
     */
    @GetMapping("/extData")
    public AjaxResult extData()
    {
        JSONObject returnData = new JSONObject();
        returnData.put("DataStatus", DataStatusEnum.getMapList());
        returnData.put("StartType", StarTypeEnum.getMapList());
        return AjaxResult.success(returnData);
    }

    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:toSayHello')")
    @PostMapping(value ="/im/toSayHello")
    public AjaxResult toSayHello(@RequestBody JSONObject jsonObject) {

        String loginUid = jsonObject.getString("loginUid");
        String msgContent = jsonObject.getString("msgContent");

        return adminHttpService.toSayHello( loginUid, msgContent);
    }

    /**
     * 获取公海数据分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantDataAllocateInfoService.selectMerchantDataAllocateInfoById(id));
    }

    /**
     * 新增公海数据分配
     */
    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:add')")
    @Log(title = "公海数据分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantDataAllocateInfo merchantDataAllocateInfo)
    {
        return toAjax(merchantDataAllocateInfoService.insertMerchantDataAllocateInfo(merchantDataAllocateInfo));
    }

    /**
     * 修改公海数据分配
     */
    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:edit')")
    @Log(title = "公海数据分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantDataAllocateInfo merchantDataAllocateInfo)
    {
        return toAjax(merchantDataAllocateInfoService.updateMerchantDataAllocateInfo(merchantDataAllocateInfo));
    }


    /**
     * 删除公海数据分配
     */
    @PreAuthorize("@ss.hasPermi('merchantdata:allocateInfo:remove')")
    @Log(title = "公海数据分配", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantDataAllocateInfoService.deleteMerchantDataAllocateInfoByIds(ids));
    }



}
